package practice.phase03.module01.mapreduce.playtime;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class PlayTimeMapper extends Mapper<LongWritable, Text, Text, PlayLogBean> {
    private Text deviceId = new Text();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, PlayLogBean>.Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split("\t");
        String deviceId = fields[1];
        this.deviceId.set(deviceId);
        Long selfDuration = Long.parseLong(fields[4]);
        Long thirdDuration = Long.parseLong(fields[5]);
        PlayLogBean playLogBean = new PlayLogBean(deviceId, selfDuration, thirdDuration);
        context.write(this.deviceId, playLogBean);
    }
}
